layui.use(["form", "laydate","layer"], function () {
    var $ = layui.jquery, form = layui.form, laydate = layui.laydate,layer=layui.layer;
    laydate.render({
        elem: '#datatime'
        , format: 'yyyy/MM/dd'
        , min: 0
    });
    var tagger=$("input[name='info']").val();
    var index = parent.layer.getFrameIndex(window.name);
    if(tagger=="true"){
        parent.location.reload();
        parent.layer.close(index);
    }
    var scheduleIds=$("input[name='scheduleIds']").val();
    var sj=$("input[name='kssj']").val();
    var typeIds=$("input[name='typeHider']").val();
    if(""!=scheduleIds&&""!=sj&&""!=typeIds){
        var id=scheduleIds.split(",");
        var tt=false;
        for (var i=0;i<id.length;i++){
            if(id[i]==typeIds){
                tt=true;
            }
        }
        if(tt==true){
            $(".layui-custom-show").hide();
            $(".layui-custom-hide").show();
            var sjs=sj.split("-");
            if(sjs[0].indexOf("08:00")!=-1){
                if(sjs[1].indexOf("17:30")!=-1){
                    $("input[name='scheduleName']").eq(1).prop("checked",true);
                }else {
                    $("input[name='scheduleName']").eq(0).prop("checked",true);
                }
            }else {
                $("input[name='scheduleName']").eq(2).prop("checked",true);
            }
        }
        form.render("radio");
    }
    form.on("radio(scheduleName)",function (data) {
        var val=data.value;
        if("1"==val){
            $("input[name='kssj']").val("08:00 - 23:00");
        }else if("2"==val){
            $("input[name='kssj']").val("08:00 - 17:30");
        }else if("3"==val){
            $("input[name='kssj']").val("17:30 - 23:00");
        }
    });
    form.on("select(type)",function (data) {
        var val=data.value;
        if(null!=scheduleIds&&""!=scheduleIds){
            var id=scheduleIds.split(",");
            var tt=false;
            for (var i=0;i<id.length;i++){
                if(id[i]==val){
                    tt=true;
                }
            }
            if(tt==true){
                $(".layui-custom-show").hide();
                $(".layui-custom-hide").show();
                $("input[name='scheduleName']").eq(0).prop("checked",true);
                $("input[name='kssj']").val("08:00 - 23:00");
            }else {
                $(".layui-custom-show").show();
                $(".layui-custom-hide").hide();
                $("input[name='kssj']").val("");
                $("input[name='scheduleName']").eq(0).prop("checked",true);
            }
        }
        form.render("radio");
    });

    var info=true;
    laydate.render({
        elem: '#kssj'
        , type: 'time'
        , format: 'HH:mm'
        , range: true
        , done: function (value, date, endDate) {
            var startTime = date.hours;
            var endTime = endDate.hours; //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            if ((startTime > endTime) || (startTime == endTime && date.minutes > endDate.minutes)) {
                layer.msg("选择时间范围有误！请重新选择");
                info=false;
            }
        }
    });
    $(".layui-custom-role").on("click",function () {
        var scheduleRoles=$("input[name='scheduleRoles']").val();
        var url="/uc/user/role/oauth";
        if(""!=scheduleRoles){
            url="/uc/user/role/oauth?idsTech="+scheduleRoles;
        }
        layer.open({
            title: "角色授权",
            type: 2,
            area: ['90%', '90%'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
    });
    $(".layui-custom-user").on("click",function () {
        var scheduleUsers=$("input[name='scheduleUsers']").val();
        var url='/uc/user/user/oauth';
        if(""!=scheduleUsers){
            url="/uc/user/user/oauth?idsTech="+scheduleUsers;
        }
        layer.open({
            title: "用户授权",
            type: 2,
            area: ['90%', '90%'],
            fixed: true, //不固定
            maxmin: true,
            content:url
        });
    });
    $(".custom-delete").on("click",function () {
        layer.confirm('确认删除本条日程吗？', {
            btn: ['取消','确认'] //按钮
        }, function(){
            layer.msg('取消成功', {icon: 1});
        }, function(){
            $("input[name='delete']").val("true");
            $(".layui-form").eq(0).submit();
        });
    });
});